import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class SwiperPro extends StatefulWidget {
  @override
  _SwiperProState createState() => _SwiperProState();
}

class _SwiperProState extends State<SwiperPro> {
  static List<Map> imgList = [
    {"url": "http://img5.mtime.cn/mg/2021/08/24/141454.81651527_285X160X4.jpg"},
    {"url": "http://img5.mtime.cn/mg/2021/08/24/134535.67957178_285X160X4.jpg"},
    {"url": "http://img5.mtime.cn/mg/2021/08/24/112722.60735295_285X160X4.jpg"},
    {"url": "http://img5.mtime.cn/mg/2021/08/24/110937.63038065_285X160X4.jpg"},
  ];

  var MySwiperWidget = Swiper(
    autoplay: true,
    onTap: (int index){
      print(index.toString());
    },
    itemBuilder: (BuildContext context, int index) {
      //每次循环遍历时，将i赋值给index
      return new Image.network(
        imgList[index]['url'],
        height: 100,
        fit: BoxFit.fill,
      );
    },
    itemCount: imgList.length,
    //指示器
    pagination: new SwiperPagination(),
  );

  @override
  Widget build(BuildContext context) {
    return Container(
        width: double.infinity,
        child: Swiper(
          autoplay: true,
          itemBuilder: (BuildContext context, int index) {
            //每次循环遍历时，将i赋值给index
            return new Image.network(
              imgList[index]['url'],
              height: 100,
              fit: BoxFit.fill,
            );
          },
          itemCount: imgList.length,
          //指示器
          pagination: new SwiperPagination(),
        ),
      );

  }
}
